import { Controller, Get, Query } from '@nestjs/common';
import { CaptchaService } from './captcha.service';
import { CaptchaChallengeDto } from './dto/captcha-challenge.dto';
import { ApiTags } from '@nestjs/swagger';

@ApiTags('captcha')
@Controller('captcha')
export class CaptchaController {
  constructor(private readonly captchaService: CaptchaService) {}

  @Get('/')
  async new() {
    return await this.captchaService.generate();
  }

  @Get('challenge')
  async challenge(@Query() dto: CaptchaChallengeDto) {
    return await this.captchaService.validate(dto.key, dto.value, true);
  }
}
